import { LOGIN_SUCCESS,LOGIN_FAIL,INIT_SUCCESS,INIT_FAIL,LOGOUT } from '../config/constant'

const home = (state = {} ,action) => {
  switch (action.type) {
    case INIT_SUCCESS:{
        return Object.assign({},state,{
          token:action.token,
          login:action.login,
          uid:action.uid,
          username:action.username
        })
    }
    case INIT_FAIL:{
      return Object.assign({},state,{
        login:action.login,
        msg:action.msg
      })
    }
    case LOGIN_SUCCESS:{
      return Object.assign({},state,{
        uid:action.uid,
        username:action.username,
        token:action.token,
        login:action.login,
        msg:action.msg
      })
    }
    case LOGIN_FAIL:{
      return Object.assign({},state,{
        login:action.login,
        msg:action.error
      })
    }
    case LOGOUT:{
      return Object.assign({},state,{
        login:action.login,
        msg:action.msg,
        token:action.token
      })
    }
    default:
    return state
  }
}

export default home
